#!/usr/bin/env python
# encoding: utf-8
"""
dbutitilies.py

Created by Bud Gibson on 2010-06-17.
Copyright (c) 2010 Bud Gibson. Available under the GPL/Artistic License.
"""

import ZODB.config
import transaction
from BTrees.OOBTree import OOBTree
try:
  from buzztracker.configuration import ZODB_CONF
except ImportError:
  import sys
  import os
  sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
  from buzztracker.conf import ZODB_CONF

def get_db(conf=ZODB_CONF):
  """Returns an OOBTree object from ZODB"""
  db = ZODB.config.databaseFromURL(conf)
  conn = db.open()
  root = conn.root()
  if not root.has_key('rundb'):
    root['rundb'] = OOBTree()
    transaction.commit()
  return root['rundb']

def main():
	rundb = get_db()
	print 'number of records:', len(rundb)

if __name__ == '__main__':
	main()

